<template>
  <div class="subscribe-page">
    <loading :show="loading" />
    <div class="text">请扫描或者识别下方二维码关注公众号</div>
    <div class="image">
      <img :src="path" />
    </div>
    <div class="login" @click="$router.push('/user/login')">立即登录</div>
  </div>
</template>

<script>
import Loading from '@/components/Loading'
import api from '@/api'
import base64 from '@/util/base64'
export default {
  name: 'Subscribe',
  components: {
    Loading
  },
  data() {
    return {
      path: '',
      loading: false
    }
  },
  methods: {
    fetchData() {
      const data = this.$store.getters['ExecUser/subscribe']
      const test = true
      // if (data === null) {
      // 这个后台要清楚下缓存
      if (test) {
        this.loading = true
        api.Exec.subscribe().then(response => {
          let { data } = response
          data = base64.parse(data)
          data = data.path
          this.$store.dispatch('ExecUser/set_subscribe', data).then(() => {
            this.path = data
            // console.log(this.path)
          })
        }).finally(() => {
          this.loading = false
        })
      } else {
        this.path = data
      }
    }
  },
  created () {
    this.fetchData()
  },
  activated() {
    this.fetchData()
  }
}
</script>

<style scoped lang="stylus">
.subscribe-page
  .text
    font-weight 700
    color red
    margin 20px
  .image
    //background white
    padding 10px
  .login
    margin 10px
    background white
    padding 15px
    font-size 14px
    letter-spacing 1.2px
    border-radius 10px
</style>
